<?php

namespace App\Http\Controllers;

use SoapClient;

class MultiplexController extends Controller
{
    const AVATAR_URL_PREFIX = '/uploads/images/avatar/';

    /**
     * SOAP web service util
     *
     * @return object SoapClient
     */
    public static function getWebServiceClient()
    {
        $options = [
            'trace'      => true,
            'exceptions' => true,
        ];

        return new SoapClient(env('WSDL_URL'), $options);
    }

    public static function getAvatarUrl()
    {
        $avatarUrl = self::AVATAR_URL_PREFIX.'default.png';

        if (! request()->has('avatar_url')) {
            return $avatarUrl;
        }

        $avatar = request('avatar_url');

        if (preg_match('#^http(s)?://#', $avatar) === 1) {
            $avatarUrl = $avatar;
        }

        return $avatarUrl;
    }

}